export const ImportReamrkString = `
我有一个文档，需要你参考我的规则来格式化文本数据，我的要求将文本按照以下示例格式输出：“
[
  { "id": 103, "type":"csmwj-group-line", "title":"普通分组", "text":"" },
  { 
    "id": 105, "type":"csmwj-radio-group", "title":"单选题", "text":"",
    "options": [
      { "value":"选项一", "score": "5" }, 
      { "value":"选项二", "score": "4"  }, 
      { "value":"选项三", "score": "3" }
    ],
    "oneanswer": { "score": "", "answer": "" }
  },
  {
    "id": 106,
    "type":"csmwj-checkbox-group",
    "title":"多选题",
    "text":"",
    "options": [
      { "value":"选项一", "score": 1 }, 
      { "value":"选项二", "score": 2 },
      { "value":"选项三", "score": 3 }
    ],
    "oneanswer": { "score": "", "answer": "" }
  },
  {
    "id": 107,
    "type":"csmwj-rightorwrong",
    "title":"判断题",
    "text":"",
    "options": [{ "value": "是" }, { "value": "否" }],
    "oneanswer": { "score": "", "answer": "" }
  },
  { 
    "id": 108,
    "type": "csmwj-score",
    "title": "选择记分",
    "text": "",
    "options": [
      { "value":"非常满意", "score": 5 }, 
      { "value":"较满意", "score": 4  }, 
      { "value":"一般", "score": 3 }, 
      { "value":"比较不满意", "score": 2 }, 
      { "value":"很不满意", "score": 1 }
    ],
    "oneanswer": { "score": "", "answer": "" }
  },
  { "id": 109, "type":"csmwj-input", "title":"填空题", "text":"请问你的姓名？" },
  { "id": 110, "type":"csmwj-input-score", "title":"填写打记分", "text":"你对他的印象分值，请输入 0-100" },
  { "id": 111, "type":"csmwj-input-fixed-score", "title":"默认记分", "text":"", "value": "10" }
]”；

其实的解释在注释里已经体现，下面是字段着重说明，以便于你理解：
中文序号项均为普通分组
id：从 100 开始自增长；
type类型如下： 
'csmwj-group-line'='普通分组',
'csmwj-radio-group'='单选题',
'csmwj-checkbox-group'='多选题',
'csmwj-rightorwrong'='判断题',
'csmwj-score'='选择记分',
'csmwj-input'='填空题',
'csmwj-input-score'='填写打记分',
'csmwj-input-fixed-score'='默认记分'；
text：“问题的题目内容”；
value：选项、结果内容；
score：分值；
oneanswer：答案 包括 记分值 和答案内容
；"
`

const templateJsonList = [
  {
    __config__: {
      label: '问卷头部',
      csmtype: 'csmwj-header', // 类型的标识
      tag: 'csmwj-header',
      tagIcon: 'radio',
      layout: 'colFormItem',
      csmwjheader: true,
      csmwjimages: true,
      csmwjtext: true,
      span: 24,
      formId: 101,
      renderKey: '1011728225590872'
    },
    __slot__: {},
    csmwjheader: {
      value: '问卷标题'
    },
    csmwjrequired: {
      value: true
    },
    csmwjimages: {
      value: []
    },
    csmwjtext: {
      value: '感谢您能抽出几分钟时间来参加本次答题，现在我们就马上开始吧！' // 题目内容
    },
    __vModel__: 'field101' // 跟随 上面的formId来的 前面追加了field
  }, {
    __config__: {
      label: '问卷底部',
      csmtype: 'csmwj-footer', // 类型的标识
      tag: 'csmwj-footer',
      tagIcon: 'radio',
      layout: 'colFormItem',
      csmwjtext: true,
      csmwjimages: true,
      span: 24,
      formId: 102, // 这个id从100开始逐个递增
      renderKey: '1021728225605344'
    },
    __slot__: {},
    csmwjheader: {
      value: '问卷标题'
    },
    csmwjtext: {
      value: '您已完成本次问卷，感谢您的帮助与支持' // 题目内容
    },
    csmwjimages: {
      value: []
    },
    __vModel__: 'field102' // 跟随 上面的formId来的 前面追加了field
  }, {
    __config__: {
      label: '分组标题',
      csmtype: 'csmwj-group-line', // 类型的标识
      tag: 'csmwj-group-line',
      tagIcon: 'radio',
      layout: 'colFormItem',
      csmwjtext: true,
      csmwjimages: true,
      span: 24,
      formId: 103, // 这个id从100开始逐个递增
      renderKey: '1031728225607544'
    },
    __slot__: {},
    csmwjheader: {
      value: '问卷标题'
    },
    csmwjtext: {
      value: '请输入分组标题'
    },
    csmwjimages: {
      value: []
    },
    __vModel__: 'field103'
  }, {
    __config__: {
      label: '打分标题',
      csmtype: 'csmwj-scoring',
      tag: 'csmwj-scoring',
      tagIcon: 'radio',
      layout: 'colFormItem',
      csmwjtext: true,
      csmwjimages: true,
      span: 24,
      formId: 104,
      renderKey: '1041728225609952'
    },
    __slot__: {},
    csmwjheader: {
      value: '问卷标题'
    },
    csmwjtext: {
      value: '请输入打分标题'
    },
    csmwjimages: {
      value: []
    },
    __vModel__: 'field104'
  }, {
    __config__: {
      label: '单选题',
      csmtype: 'csmwj-radio-group',
      tag: 'csmwj-radio-group',
      tagIcon: 'radio',
      layout: 'colFormItem',
      csmwjtitle: true,
      csmwjimages: true,
      csmwjrequired: true,
      csmwjoptions: true,
      csmwjshowscore: true,
      span: 24,
      formId: 105,
      renderKey: '1051728225612272'
    },
    __slot__: { // 选项
      options: [{
        value: '选项一',
        score: 0
      }, {
        value: '选项二',
        score: 0
      }, {
        value: '选项三',
        score: 0
      }]
    },
    csmwjtitle: {
      value: '请选择一个选项'
    },
    csmwjrequired: {
      value: true
    },
    csmwjoptions: {
      value: null
    },
    csmwjimages: {
      value: []
    },
    csmwjshowscore: {
      value: false,
      method: null,
      oneanswer: {
        score: null,
        answer: null
      },
      analysis: null,
      showscore: null
    },
    __answer__: {
      value: null,
      text: null
    },
    __vModel__: 'field105'
  }, {
    __config__: {
      label: '多选题',
      csmtype: 'csmwj-checkbox-group',
      tag: 'csmwj-checkbox-group',
      tagIcon: 'checkbox',
      layout: 'colFormItem',
      csmwjtitle: true,
      csmwjimages: true,
      csmwjrequired: true,
      csmwjoptions: true,
      csmwjshowscore: true,
      span: 24,
      formId: 106,
      renderKey: '1061728225614774'
    },
    __slot__: { // 选项
      options: [{
        value: '选项一',
        score: 0
      }, {
        value: '选项二',
        score: 0
      }, {
        value: '选项三',
        score: 0
      }]
    },
    csmwjtitle: {
      value: '请选择一个选项',
      image: []
    },
    csmwjrequired: {
      value: true
    },
    csmwjimages: {
      value: []
    },
    csmwjshowscore: {
      value: null,
      method: null,
      oneanswer: {
        score: null,
        answer: null
      },
      analysis: null,
      showscore: null
    },
    __answer__: [],
    __vModel__: 'field106'
  }, {
    __config__: {
      label: '判断题',
      csmtype: 'csmwj-rightorwrong', // 唯一标识
      tag: 'csmwj-radio-group',
      tagIcon: 'radio',
      layout: 'colFormItem',
      csmwjtitle: true,
      csmwjimages: true,
      csmwjrequired: true,
      csmwjoptions: true,
      csmwjshowscore: true,
      span: 24,
      formId: 107,
      renderKey: '1071728225619015'
    },
    __slot__: { // 选项
      options: [{
        value: '是'
      }, {
        value: '否'
      }]
    },
    csmwjtitle: {
      value: '请选择一个选项'
    },
    csmwjrequired: {
      value: true
    },
    csmwjimages: {
      value: []
    },
    csmwjshowscore: {
      value: null,
      method: null,
      oneanswer: {
        score: null,
        answer: null
      },
      analysis: null,
      showscore: null
    },
    __answer__: {
      value: null,
      text: null
    },
    __vModel__: 'field107'
  }, {
    __config__: {
      label: '打分题',
      csmtype: 'csmwj-score',
      tag: 'csmwj-radio-group',
      tagIcon: 'radio',
      layout: 'colFormItem',
      csmwjtitle: true,
      csmwjimages: true,
      csmwjrequired: true,
      csmwjPlusOptionAndScore: true,
      span: 24,
      formId: 108,
      renderKey: '1081728225621969'
    },
    __slot__: {
      options: [{
        value: '非常满意',
        score: '5'
      }, {
        value: '较满意',
        score: '4'
      }, {
        value: '一般',
        score: '3'
      }, {
        value: '比较不满意',
        score: '2'
      }, {
        value: '很不满意',
        score: '1'
      }]
    },
    csmwjtitle: {
      value: '请选择一个选项'
    },
    csmwjrequired: {
      value: true
    },
    csmwjimages: {
      value: []
    },
    csmwjshowscore: {
      value: true,
      method: 'everyscore',
      oneanswer: {
        score: null,
        answer: null
      },
      analysis: null,
      showscore: true
    },
    __answer__: {
      value: null,
      text: null
    },
    __vModel__: 'field108'
  }, {
    __config__: {
      label: '单选填空题',
      csmtype: 'csmwj-input',
      tag: 'csmwj-input',
      tagIcon: 'input',
      layout: 'colFormItem',
      csmwjtitle: true,
      csmwjimages: true,
      csmwjrequired: true,
      csmwjinput: true,
      span: 24,
      formId: 109,
      renderKey: '1091728225629433'
    },
    __slot__: {},
    csmwjtitle: {
      value: '请填写以下内容'
    },
    csmwjrequired: {
      value: true
    },
    csmwjimages: {
      value: []
    },
    csmwjinput: {
      value: null,
      inputtype: 'input',
      format: 'text',
      format_text_minlength: 0,
      format_text_maxlength: 255,
      format_number_decimal_length: 2,
      format_number_min: 0,
      format_number_max: 999,
      format_regex: null,
      format_regex_errormsg: null
    },
    __answer__: {
      value: null
    },
    __vModel__: 'field109'
  }, {
    __config__: {
      label: '填写打分题',
      csmtype: 'csmwj-input-score',
      tag: 'csmwj-input-score',
      tagIcon: 'input',
      layout: 'colFormItem',
      csmwjtitle: true,
      csmwjimages: true,
      csmwjrequired: true,
      csmwjinput: true,
      span: 24,
      formId: 110,
      renderKey: '1101728225632520'
    },
    __slot__: {},
    csmwjtitle: {
      value: '请填写以下内容'
    },
    csmwjrequired: {
      value: true
    },
    csmwjimages: {
      value: []
    },
    csmwjinput: {
      value: null,
      inputtype: 'input',
      format: 'number',
      format_text_minlength: 0,
      format_text_maxlength: 999,
      format_number_decimal_length: 2,
      format_number_min: 0,
      format_number_max: 100,
      format_regex: null,
      format_regex_errormsg: null
    },
    __answer__: {
      value: null
    },
    __vModel__: 'field110'
  }, {
    __config__: {
      label: '固定打分题',
      csmtype: 'csmwj-input-fixed-score',
      tag: 'csmwj-input-fixed-score',
      tagIcon: 'input',
      layout: 'colFormItem',
      csmwjtitle: true,
      csmwjimages: true,
      csmwjrequired: true,
      csmwjinput: true,
      span: 24,
      formId: 111,
      renderKey: '1111728225635184'
    },
    __slot__: {},
    csmwjtitle: {
      value: '请填写以下内容'
    },
    csmwjrequired: {
      value: true
    },
    csmwjimages: {
      value: []
    },
    csmwjinput: {
      value: null,
      inputtype: 'input',
      format: 'number',
      format_text_minlength: 0,
      format_text_maxlength: 999,
      format_number_decimal_length: 2,
      format_number_min: 0,
      format_number_max: 100,
      format_regex: null,
      format_regex_errormsg: null
    },
    __answer__: {
      value: null
    },
    __vModel__: 'field111'
  }
]

const templateJsonObject = templateJsonList.reduce((o, v) => {
  const obj = {}
  obj[v.__config__.csmtype] = v
  return { ...o, ...obj }
}, {})

function renderJson(data) {
  return data.reduce((a, v) => {
    const target = JSON.parse(JSON.stringify(templateJsonObject[v.type]))
    if (target.csmwjtext) {
      target.csmwjtext.value = v?.text || v?.title || target.csmwjtext?.value
    }
    if (target.csmwjtitle) {
      target.csmwjtitle.value = v?.text || v?.title || target.csmwjtitle?.value
    }
    if (target.csmwjheader) {
      target.csmwjheader.value = v.title || target.csmwjheader?.value
    }
    target.__vModel__ = `field${v.id}`
    target.__config__.formId = v.id
    if (v.options) {
      target.__slot__.options = v.options
    }
    if (v.oneanswer) {
      target.csmwjshowscore.oneanswer = v.oneanswer
    }
    return [...a, target]
  }, [])
}

export default renderJson
